#ifndef FILESYSTEM_H_
#define FILESYSTEM_


#include <cstdlib>
#include "MyDisk.h"
#include<string>
#include <iostream>

#include <stdio.h>
#include <stdlib.h>

#include <list>
using namespace std;

class FileSystem
{
public:
	MyDisk* disk;

	FileSystem();
	FileSystem(int _diskSize, int _blockSize, int _numOfNodes);
	virtual ~FileSystem();




/****THE FILE SYSTEM FUNCTIONS************/
	int createFile (char flag);

	int createDir();

	char getFileType(int inode);

	int f_write(int inode , char* buffer , int offset , int nBytes);

	int f_read(int inode , char* buffer , int offset , int nBytes);

	int d_write(int inode , list<pair<int,char*> >* dirList);

	list<pair<int,char*> >* d_read(int inode);


	int f_delete(int inode);

	int d_delete(int inode);


/*MY HELPING FUNCTIONS*/

	MyDisk* getMyDisk();

	bool isEmptyDir(int inode);

	bool isBlockAllocFile(int inode,int index);

	/**
	 * writng to the block , set the size and returning the written bytes.
	 */
	int writeAndSet(char * buffer,int blockIndex,int block ,int offsetInBlock ,int nBytes, int inode);


	/**
	 * filling with zero the file to let you write in the middle of a file
	 */
	int fillHole(int inode , int EndOfHole);

	char* itoa (int n);

	 int listToString(list<pair<int,char*> >* lstDir, char* str);
	 /**
	  * asymetric of vecListToString
	  */
	void  stringToList(list<pair<int,char*> >* lstDir,char* str);

	/**
	 * return -1 if not existent
	 */
	int getInodeNumber(char * name,list<pair<int,char*> >* lstDir);

	int makeValidName(char* name );


	int strCopy(char* dest , char* source , int n);
	int  memChar(char* str , char x,int n);
	int strComp(char* dest, char* source ,int n);

/**PRINTING FUNCTIONS**/


	 void printFile(int inode);

	// void printDirectoryList(list<pair<int,char*> >* lstDir);


};
#endif /*FILESYSTEM_H_*/
